<?php
/**
 * Main Company Screen
 * This page display on the left a menu and on the right the content
 * of the page.
 * 
 * 
 * @author Xavier VILAIN
 * @package Hive\Company
 */
use Hive\Company;
use Fox\Html\Wrapper;
use Fox\Core\Errors;
use Fox\Generator;
use Fox\Html\Navigation\Menu\Item;
use Fox\Html\Navigation\Menu\Item\Sub;
use Fox\Html\Navigation\Menu;

/* @var $company Hive\Company */
$company = Xview::instance()->component(Company::BUNDLE, "object");
if(!$company->exists()) {
	exit;
}
$id = $company->getId();
$resData = $company->getData();
$documentsNb = $company->countDocuments();
$tasksNb = count($company->tasks());
// 
$contactsCounters = $company->countContacts();
$subCompanyNb = $company->countSubCompanies();

$defaultPage = "detail";
// Main Config
$page = Xview::instance()->val("page","detail");
$master = Company::BUNDLE;
$action = "main";

$wrapper = new Wrapper('leftCol');
$favMenu = new Menu('leftMenu',Msg(Hive::BUNDLE,Hive::COMPANY_MENU_STANDARD));
$wrapper->add($favMenu);
		
// Detail
$favMenu->add(new Item('detail',Msg(Hive::BUNDLE,Hive::COMPANY_MENU_DETAIL),
						Generator::url($master,'detail',null,array('cpid' => $id)),
						null,'personnal'));
// Contacts / VIP
$favMenu->add(new Item('contacts-vip',Msg(Hive::BUNDLE,Hive::VIP_CONTACTS),
						Generator::url($master,'contacts','vip',
							array('cpid' => $id)),$contactsCounters['vip']));						
// Contacts / All
$favMenu->add(new Item('contacts-all',Msg(Hive::BUNDLE,Hive::MENU_CONTACTS),
						Generator::url($master,'contacts','all',
							array('cpid' => $id)),$contactsCounters['all'],'contacts'));
// Contacts / Old
$favMenu->add(new Item('contacts-old',Msg(Hive::BUNDLE,Hive::OLD_CONTACTS),
						Generator::url($master,'contacts','old',
							array('cpid' => $id)),$contactsCounters['old'],'contacts-old'));
// Linked Companies	
$favMenu->add(new Item('childrens',Msg(Hive::BUNDLE,Hive::SUB_COMPANIES),
						Generator::url($master,'childrens',null,
							array('cpid' => $id)),
					$subCompanyNb,'workflow'));
// Documents
/*				
$favMenu->add(new Item('documents',Msg(Hive::BUNDLE,Hive::MENU_DOCUMENTS),
						Generator::url($master,'documents',null,
							array('cpid' => $id)),
					$documentsNb));
*/	

				
// Tasks
$favMenu->add(new Item('tasks',Msg(Hive::BUNDLE,Hive::TITLE_TASKS),
						Generator::url($master,'tasks',null,
							array('cpid' => $id)),
					$tasksNb));
					
$toolsMenu = new Menu('toolsMenu',Msg(Hive::BUNDLE,Hive::MENU_TOOLS));
$toolsMenu->add(new Item('tools-merge',
							Msg(Hive::BUNDLE,Hive::MENU_MERGE),
							Generator::url($master,'tools','merge',
							array('cpid' => $id)),null,'merge'));
$wrapper->add($toolsMenu);
							
$edit = '<div id="leftColContainer">
			<div id="leftCol">
			<div id="pagelet_welcome_box">
				<div class="hive-missions-box">
				</div>
			</div>
			<div id="pagelet_navigation">
				<div class="uiFutureSideNav">
				'.$wrapper->render().'
			</div>
		</div>
		</div>';

if(isset($_GET['uri']) && !empty($_GET['uri']))
{
	$parts = explode('-', $_GET['uri']);
	if(count($parts) > 2) {
		$url = Generator::url($parts[0],$parts[1],$parts[2]);
		$page = $parts[1].'-'.$parts[2];
	} else {
		$url = Generator::url($parts[0],$parts[1]);
		$page = $parts[1];
	}
	
	if(!Xview::instance()->isModule($url)) {
		$url = null;
	}
}
if(empty($url)) {
	$params = array('return' => true);
	list($url,$page) = \Hive\Company\Customizing::instance()->defaultSummaryPage($params);
}
$item = $wrapper->item($page);
if(!empty($item)) {
	$wrapper->item($page)->selected();
}
?>
<div id="leftColContainer" >
	<div id="leftCol">
		<div id="pagelet_welcome_box">
			<div class="hive-contact-box">
				<div class="clearfix uiImageBlock fbxWelcomeBox">
					<a href="?mod=company&act=main&page=detail&uri=company-detail&cpid=<?php echo $id;?>" class="uiImageBlockMediumImage lfloat slink">
						<img class="fbxWelcomeBoxImg  img" src="<?php echo $company->logo();?>" />
					</a>
					<div class="uiImageBlockContent" >
						<span class="title"><?php echo $company->name(); ?></span>
						<div class="i"><?php echo $company->category(); ?></div>
					</div>
				</div>			
			</div>
		</div>
		<div id="pagelet_navigation">
			<div class="uiFutureSideNav">
			<?php echo $wrapper->render(); ?>
			</div>
		</div>
	</div>
</div>
<div id="contentCol" class="hasLeftCol">
	<?php echo Xview::instance()->display($url); ?>
</div>